﻿using System.Collections.Generic;
using System.Text;
using System.Data;
using PPI.Data;
using PPI.Entities;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;

namespace PPI.ServiceLogic
{
    public class LVendor_Contacts : IMobileTable
    {
        public static List<EVendor_Contact> SelectAllIdNameByVendor(int vendorID, string connectionKey)
        {
            List<EVendor_Contact> _VendorContactList = new List<EVendor_Contact>();
            EVendor_Contact _VendorContact;
            DataSet ds = DVendor_Contacts.SelectAllIdNameByVendor(vendorID,connectionKey);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                _VendorContact = new EVendor_Contact();
                _VendorContact.Vendor_ContactId = ConvertHelper.ToInt32(dr["Vendor_ContactId"]);
                _VendorContact.Name = ConvertHelper.Tostring(dr["Name"]);
                _VendorContact.Vendor = new EVendor(ConvertHelper.ToInt32(dr["VendorFK"]));
                _VendorContactList.Add(_VendorContact);
            }
            return _VendorContactList;
        }

        public static List<EVendor_Contact> SelectAllIdName(string connectionKey)
        {
            return SelectAllIdNameByVendor(0, connectionKey);
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            listQueries.Add(new EMobileQuery("Delete tb_Users"));
            DataTable dt = DVendor_Contacts.SelectAllIdNameByVendor(0, connectionKey).Tables[0];
            foreach (DataRow dr in dt.Rows)
                listQueries.Add(new EMobileQuery("insert into tb_Users values (" + ConvertHelper.ToInt32(dr["Vendor_ContactId"]) + "," + ConvertHelper.ToInt32(dr["VendorFK"]) + ",'" + ConvertHelper.Tostring(dr["Name"]) + "')"));

            return listQueries;
        }
    }
}
